package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.OrderSale;
import com.sumi.erp.service.IOrderSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 销售订单Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/sales/sale")
public class OrderSaleController extends BaseController
{
    @Autowired
    private IOrderSaleService orderSaleService;

    /**
     * 查询销售订单列表
     */
    @PreAuthorize("@ss.hasPermi('sales:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderSale orderSale)
    {
        startPage();
        List<OrderSale> list = orderSaleService.selectOrderSaleList(orderSale);
        return getDataTable(list);
    }

    /**
     * 导出销售订单列表
     */
    @PreAuthorize("@ss.hasPermi('sales:sale:export')")
    @Log(title = "销售订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderSale orderSale)
    {
        List<OrderSale> list = orderSaleService.selectOrderSaleList(orderSale);
        ExcelUtil<OrderSale> util = new ExcelUtil<OrderSale>(OrderSale.class);
        util.exportExcel(response, list, "销售订单数据");
    }

    /**
     * 获取销售订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('sales:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderSaleService.selectOrderSaleById(id));
    }

    /**
     * 新增销售订单
     */
    @PreAuthorize("@ss.hasPermi('sales:sale:add')")
    @Log(title = "销售订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderSale orderSale)
    {
        return toAjax(orderSaleService.insertOrderSale(orderSale));
    }

    /**
     * 修改销售订单
     */
    @PreAuthorize("@ss.hasPermi('sales:sale:edit')")
    @Log(title = "销售订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderSale orderSale)
    {
        return toAjax(orderSaleService.updateOrderSale(orderSale));
    }

    /**
     * 删除销售订单
     */
    @PreAuthorize("@ss.hasPermi('sales:sale:remove')")
    @Log(title = "销售订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderSaleService.deleteOrderSaleByIds(ids));
    }
}
